#include <vector>
#include <iostream>
#include <string>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;
using namespace std;
vector<Product> products;    //目标图像
std::vector<Defect> defects; //目标缺陷
int pid = 1;

int main(int argc, char const *argv[])
{
    if (argc != 2)
        return 0;

    cv::VideoCapture cap(argv[1]); //构造读取视频的对象，并构造函数赋值
    if (!cap.isOpened())
    {
        std::cout << "打开失败!!" << std::endl;
        return -1;
    }

    cv::Mat img, gray, thresh;
    bool new_object;
    while (cap.read(img)) //有读到时视频信息时
    {
        if (!cap.read(img)) //cap.read读取图像存入img
        {
            cap.set(cv::CAP_PROP_POS_FRAMES, 0);
            continue;
        }

        cvtColor(img, gray, COLOR_BGR2GRAY);
        threshold(gray, thresh, 127, 255, THRESH_TOZERO_INV);

        // imshow("result", thresh);
        //边缘检测，识别工件
        std::vector<Vec4i> hireachy;
        std::vector<std::vector<Point>> contours;
        findContours(thresh, contours, hireachy, RETR_LIST, CHAIN_APPROX_NONE);

        vector<Moments> mu(contours.size());
        vector<Rect> boundRect(contours.size());

        for (size_t cnt = 0; cnt < contours.size(); cnt++)
        {
      
        }
        
        imshow("img", img);
        char c = cv::waitKey(100);
        if (c == 27) //按esc退出
        {
            break;
        }
    }
    cap.release(); //一定要释放！！！
    return 0;
}
